import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.widgets.Canvas;


public class Box {
	
	private String name;
	private Position position;
	private boolean isDown = true;
	private int side; //size of side of box
	
	//c'tors
	public Box(String name, Position p){
		position = p;
		this.name = name;
		//calculate the size of the box's side
		side = (int)Math.round(Math.sqrt(200));
	}
	
	public Box(String name){
		position = new Position();
		this.name = name;
	}
	//checks if box is down
	public boolean isDown() {return isDown;}
	//sets box's state to down
	public void setToDown() {isDown = true;}
	//sets box's state to up
	public void setToUp() {isDown = false;}
	//returns name
	public String getName() {return name;}
	
	public void setPosition(Position p) { position.set(p);}
	public Position getPosition() { return position;}
	
	//draw box
	public void paint(PaintEvent e){
		Canvas c = (Canvas)e.widget; // get the canvas
		int maxX = c.getSize().x;	 // max size
		int maxY = c.getSize().y;
		
		int mx = maxX/2,my = maxY/2;// mid point as (0,0)
		int myX = mx + position.x;	// set the current position
		int myY = my - position.y;	// set the current position
		
		e.gc.drawRectangle(myX - (side/2), myY - (side/2), side ,side);	// draw the box
		e.gc.drawString("B", myX - 3, myY - 7,true);
		
		// the info - print if not being carried
		if(isDown){
			e.gc.drawString(name, myX+13, myY-13,true); //name
			e.gc.drawString("("+position.toString()+")",myX + 13, myY,true); //position
		}
		
		
	}
}
